package com.khshop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.khshop.pojo.Carousel;
import com.khshop.mapper.CarouselMapper;
import com.khshop.service.CarouselService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.khshop.vo.ServiceResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * <p>
 * 轮播图 服务实现类
 * </p>
 *
 * @author zhaoyang
 * @since 2020-10-16
 */
@Service
public class CarouselServiceImpl extends ServiceImpl<CarouselMapper, Carousel> implements CarouselService {
    @Autowired(required = false)
    CarouselMapper carouselMapper;

    //新增地址
    public ServiceResult<Carousel> addCarousel(Carousel carousel){
        return ServiceResult.of(carouselMapper.insert(carousel)>0);

    }

    //修改地址
    public ServiceResult<Carousel> updateCarousel(Carousel carousel){
        return ServiceResult.of(carouselMapper.updateById(carousel)>0);

    }

    //删除地址
    public ServiceResult<Carousel> delCarousel(Integer id){
        return ServiceResult.of(carouselMapper.deleteById(id)>0);

    }


    //查询地址
    public ServiceResult<IPage<Carousel>> searchCarousel(String title, Integer page, Integer limit){
        QueryWrapper<Carousel> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("title",title);
        Page<Carousel> iPage = new Page<Carousel>(page, limit);
        IPage<Carousel> orderIPage = carouselMapper.selectPage(iPage, queryWrapper);
        return ServiceResult.of(orderIPage,orderIPage.getSize()>0);

    }
}
